<template>
  <a-modal title="导入尺寸单" :visible="true" width="70%" :footer="null" @cancel="reset()"> 
    <a-button type="primary" :disabled="hasSelected" @click="handleSubmit">确认导入</a-button>
    <a-table
      :scroll="{x:1500}"
      :loading="loading"
      :column="columnCraft"
      :data-source="craftList"
      :rowSelection="{selectedRowKeys:selectedRowKeys, onChange: onSelectedChange, type:'radio'}"
      :row-key="record=>record.id"
      >

    </a-table>
  </a-modal>
</template>

<script>
import {getList} from '@api/rd/index'

const columnCraft = [
  {
    title:'工艺单号',
    dataIndex:'code'
  },
  {
    title:'单据编号',
    dataIndex:'billNo'
  },
  {
    title:'上货季',
    dataIndex:'scseason'
  },
  {
    title:'品牌',
    dataIndex:'brand'
  },
  {
    title:'小类',
    dataIndex:'xl'
  },
  {
    title:'样衣号',
    dataIndex:'sampleCode'
  },
  {
    title:'品名',
    dataIndex:'sampleName'
  },
  {
    title:'版次',
    dataIndex:'bc'
  },
  {
    title:'颜色',
    dataIndex:'stycolorid'
  }
]

export default {
  props: {
    content: {
      type: Object,
      default: null
    },
    arr: {
      type: Array,
      default: []
    }
  },
  data(){
    return{
      columnCraft,
      sealBillNo: '',
      ksBillNo: '',
      craftBillId: '',
      craftList: {},
      loading: false,
      hasSelected: false,
      selectedRowKeys: '',
      selectionRows: []
    }
  },
  mounted(){
    // this.getCraftList()
    this.craftList = this.arr
  },
  computed:{
    userInfo(){
      return this.$store.getters.userInfo || null
    }
  },
  created(){

  },
  methods: {
    async reset(){
        this.$form.resetFields()
        this.$emit('closeImport')
    },
    async onSelectedChange(selectedRowKeys,selectionRows){
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    async handleSubmit(){
      console.log(this.selectedRowKeys)
      console.log(this.selectionRows)
    },
    async getCraftList(){
      const {content} = this.$props
      if(content){
        this.ksBillNo = content.ksBillNo
        this.sealBillNo = content.sealBillNo
      }
      this.loading = true
      const params = {
        billNo : this.ksBillNo
      }
      try{
        const res = await getList('bill',params)
        if(res.code == 200){
          this.craftList = res.data.records
        } else { 
          if(res.msg){
            this.$message.error(res.msg)
          } else {
            this.$message.error("获取工艺单列表失败！")
          }
        }
      } catch (error){
        this.$message.error("获取工艺单列表失败！")
      } finally {
        this.loading = false
      }
    }
  }
}
</script>